<template>
  <div class="pages-container">

    <!-- 搜索框 Or 工具框 -->
    <a-form class="pages-tools-box" :form="form" @submit="getSearch">
      <a-row :gutter="[15, 10]">
        <a-col :span="4">
          <a-form-item>
            <a-input allowClear placeholder="订单编号" v-decorator="['orderNum']"/>
          </a-form-item>
        </a-col>
        <a-col :span="4">
          <a-form-item>
            <a-input allowClear placeholder="手机号" v-decorator="['mobile']"/>
          </a-form-item>
        </a-col>
        <a-col :span="4">
          <a-form-item>
            <a-input allowClear placeholder="姓名" v-decorator="['name']"/>
          </a-form-item>
        </a-col>
        <a-col :span="4">
          <a-form-item>
            <a-input allowClear placeholder="公司名称" v-decorator="['company']"/>
          </a-form-item>
        </a-col>
        <a-col :span="4">
          <a-form-item>
            <a-select allowClear placeholder="选择状态" v-decorator="['state']">
              <a-select-option :value="v.id" v-for="(v, i) in Config.Receipt" :key="i">{{ v.title }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="24" :style="{ textAlign: 'right' }">
          <a-button type="primary" html-type="submit">搜索</a-button>
          <a-button :style="{ marginLeft: '8px' }" @click="handleReset">清空</a-button>
        </a-col>
      </a-row>
    </a-form>

    <!-- 表格 -->
    <div class="pages-content">
      <a-table :columns="columns" :data-source="data" :pagination="false" rowKey="id" :loading="tableLoading">
        <a-space slot="price" slot-scope="row">{{row.pay && row.pay.price - row.pay.noPrice}}</a-space>
        <a-space slot="state" slot-scope="row">{{row.state | ReceiptToLabel}}</a-space>
        <a-space slot="action" slot-scope="text,record,index">
          <a @click="message(record, index)">开票信息</a>
          <a v-if="record.state == 1" @click="ok(record, index)">处理开票</a>
        </a-space>
      </a-table>
    </div>

    <!-- 分页 -->
    <a-pagination class="pagination" show-quick-jumper :default-current="current_page" :total="total"
                  @change="changePages"/>

    <!-- 开票信息 -->
    <a-modal
        title="开票信息"
        :visible="visible"
        @ok="visible = false"
        @cancel="visible = false"
    >
      <p>开票类型：电子发票</p>
      <p>发票抬头：单位</p>
      <p>单位名称：{{ modalData.title }}</p>
      <p>发票税号：{{ modalData.num }}</p>
      <p>注册地址：{{ modalData.address }}</p>
      <p>注册电话：{{ modalData.tel }}</p>
      <p>开户银行：{{ modalData.bank }}</p>
      <p>电话：{{ modalData.mobile }}</p>
      <p>邮箱：{{ modalData.email }}</p>
    </a-modal>
  </div>
</template>

<script>
const columns = [
  {title: '所属交付订单ID', dataIndex: 'payId'},
  {title: '开票金额', scopedSlots: {customRender: 'price'}},
  {title: '状态', scopedSlots: {customRender: 'state'}},
  {title: '操作', scopedSlots: {customRender: 'action'}},
];

import config from "../../tools/config";

export default {
  name: "PayList.vue",
  data() {
    return {
      // 公用配置
      Config: {},
      // 分页数据
      current_page: 1,
      total: 100,
      // table数据
      tableLoading: false,
      columns,
      data: [],
      // 搜索表单
      form: this.$form.createForm(this),
      // other
      UserStateList: [],
      visible: false,
      modalData: {},
    };
  },
  created() {
    this.Config = config
    this.getData()
  },
  methods: {

    /**
     * 进行搜索
     * @param e
     */
    getSearch(e) {
      e.preventDefault();
      this.form.validateFields((error) => {
        if (!error) {
          this.getData(1)
        }
      });
    },

    /**
     * 请求Table数据
     * @param pages
     */
    getData(pages = 1) {
      this.tableLoading = true
      this.Http.get('/admin/invoiceOrder/index', {
        page: pages,
        ...this.form.getFieldsValue()
      }).then(res => {
        this.tableLoading = false
        if (res.code === 1) {
          this.data = res.data.data
          this.current_page = res.data.current_page
          this.total = res.data.total
        } else {
          this.$message.error(res.msg)
        }
      }).catch(() => {
        this.tableLoading = false
      })
    },

    /**
     * 切换分页时
     * @param event
     */
    changePages(event) {
      this.getData(event)
    },

    /**
     * 清空搜索项
     */
    handleReset() {
      this.form.resetFields();
      this.getData()
    },

    /**
     * 已开票
     * @param row
     * @param index
     */
    ok(row, index) {
      const _this = this
      this.$confirm({
        title: '提示',
        content: '是否确认已经开票',
        onOk() {
          _this.Http.get("/admin/invoiceOrder/state", {
            id: row.id,
            state: 3
          }).then(res => {
            if (res.code == 1) {
              _this.getData(_this.current_page)
              _this.$message.success(res.msg)
            } else {
              _this.$message.error(res.msg)
            }
          })
        },
        onCancel() {
        },
      })
    },

    /**
     * 开票信息
     * @param row
     * @param index
     */
    message(row ,index){
      this.modalData = row
      this.visible = true
    },

  },
}
</script>

<style scoped>

</style>
